import { createStore, storeKey } from 'vuex'
import axios from 'axios'

export default createStore({
  state: {
    scene:1,//场景
    pdaoList:[],//频道公司
    smalltext:'',//活动说明
    maxlist:0,//最大队列
    nowlist:[],//当前队列
    isPlaying:false
  },
  getters: {
  },
  mutations: {
    // setBase(arr){
    //   state.pdaoList=arr.pdaoList
    // }
    setBase(state,arr){
      console.log('写入频道数据')
      state.maxlist=arr.maxlist
      state.smalltext=arr.description
    },
    setPdlist(state,arr){
      console.log('写入频道数据')
      state.pdaoList=arr
    },
    setScene(state,val){
      console.log('写入场景')
      state.scene=val
      sessionStorage.setItem('scene',val)

    },
    dianBo(state,arr){
      console.log('点播')
      state.nowlist=arr
      sessionStorage.setItem('nowlist',JSON.stringify(arr))
    }
  },
  actions: {
    baseData(store){
      axios.get('/api/api/index').then((response)=>{
        store.commit('setBase',response.data)
        sessionStorage.setItem('baseData',JSON.stringify(response.data))
      })
      //store.commit('setBase',2)
    },
    dianBo(store,args){
      if(store.state.nowlist.length>=store.state.maxlist){
        //return false
      }
      axios.post('/api/api/dianbo',{scene:store.state.scene,id:args,user_id:1}).then((response)=>{
        store.commit('dianBo',response.data)
      })
    },
    pdList(store,scene){
      axios.post('/api/api/pdlist',{pid:store.state.scene}).then((response)=>{
        store.commit('setPdlist',response.data)
        sessionStorage.setItem('pdaoList',JSON.stringify(response.data))
      })
    }
  },
  modules: {
  }
})
